AddCSLuaFile( "shared.lua" )


SWEP.PrintName = "Weldball"
SWEP.Slot = 3
SWEP.SlotPos = 8
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true

SWEP.Author = "_Kilburn"
SWEP.Contact = ""
SWEP.Purpose = "Attracts props and welds them into a ball shape"
SWEP.Instructions = "Left click to throw, right click to detonate dead weldballs."

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.ViewModel = "models/weapons/v_gravball.mdl"
SWEP.WorldModel = "models/weapons/w_gravball.mdl"

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

function SWEP:Initialize()
	util.PrecacheModel( "models/weapons/w_gravball.mdl" )
	util.PrecacheSound( "weapons/slam/throw.wav" )
	if (SERVER) then self:SetWeaponHoldType( "grenade" ) end
end

function SWEP:PrimaryAttack()

	local gNade = ents.Create( "npc_weldball_proj" )
		gNade:SetOwner( self:GetOwner() )
		gNade:SetPhysicsAttacker( self:GetOwner() )
		gNade:SetPos( self.Owner:GetShootPos() )
		gNade:SetAngles( self.Owner:GetAimVector() )
		gNade:Spawn()
		gNade:Activate()
	
	local gPhys = gNade:GetPhysicsObject()
	gPhys:ApplyForceCenter( self.Owner:GetAimVector() * 5000 )
	
	self.Weapon:EmitSound("weapons/slam/throw.wav" )
	self.Weapon:SendWeaponAnim( ACT_VM_THROW )
	timer.Simple( 3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
	
	self.Weapon:SetNextPrimaryFire( CurTime() + 2 )
	self.Weapon:SetNextSecondaryFire( CurTime() + 2 )
	
end

function SWEP:SecondaryAttack()
	if (SERVER) then
		for _,contact in pairs(ents.FindByClass("npc_weldball_proj_dead")) do
			if contact:GetOwner() == self:GetOwner() then
				contact:Explode()
			end
		end
	end
end

function SWEP:Reload()
	return false
end

function SWEP:Think()

end

